home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
4_0
/
DIALOGUT
/
DIALOGUT.C
next >
Wrap
Text File
|
1990-09-05
|
3KB
|
127 lines
/*
* DialogUtils.c
*
From engber@gumball.ils.nwu.edu Tue Apr 17 12:15:17 1990
From: engber@gumball.ils.nwu.edu (Mike Engber)
Newsgroups: comp.sys.mac.programmer
Subject: Centering DLOGs & ALRTs - new & improved source
Summary: multiple monitor support & better vertical placement
Date: 16 Apr 90 22:11:08 GMT
Reply-To: engber@gumball (Mike Engber)
Organization: The Institute for the Learning Sciences
I've fixed up my DLOG/ALRT centering code along the lines suggested by
Alex Kazim from Apple.
1) They are now vertically placed so that 1/3 of the open space is above.
2) If there are multiple monitors they will show up on the screen which
contains the cursor. I could have just as easily gone for the screen
with the active window, but I used GetMouse() since you normally interact
with DLOGs & ALRTs via the mouse.
Attached are the relevant portions of DialogUtils.h & DialogUtils.c.
Permission granted to do what you want with the code (even building
nuclear weapons)
-ME
*/
#include "DialogUtils.h"
#include <MemoryMgr.h>
#include <OSUtil.h>
#include <StdFilePkg.h>
#include <Color.h>
static Rect ScreenBounds(void)
{
register BitMap *myScreenBits;
asm {
move.l CurrentA5, a0
move.l (a0), myScreenBits
add.l #-122, myScreenBits
}
return myScreenBits->bounds;
}
static Rect DU_MouseGDRect(void){
/* Returns the gdRect of the screen device the mouse is currently in. */
Point p;
Rect r = ScreenBounds();
GDHandle curDevice;
SysEnvRec world;
if (SysEnvirons(curSysEnvVers, &world) == noErr && world.hasColorQD) {
curDevice = GetDeviceList();
GetMouse(&p);
while(curDevice){
if( TestDeviceAttribute(curDevice,screenDevice) &&
TestDeviceAttribute(curDevice,screenActive) &&
PtInRect(p,&(*curDevice)->gdRect)){
r = (*curDevice)->gdRect;
}
curDevice = GetNextDevice(curDevice);
}
}
return r;
}
static void DU_CenterRect(Rect* rect_p){
/*
* Alligns *rect_p wrt screenBits.bounds - LR centered & with 1/3 of the
* empty space above the rect.
*/
Rect bRect = DU_MouseGDRect();
bRect.top += GetMBarHeight();
/* exactly centered */
OffsetRect(rect_p,
(bRect.right + bRect.left)/2 - (rect_p->right + rect_p->left)/2,
(bRect.top + bRect.bottom)/2 - (rect_p->top + rect_p->bottom)/2);
/* 1/2 empty space above -> 1/3 empty space above */
OffsetRect(rect_p,0,-(rect_p->top - bRect.top)/3);
}
static Point DU_Where(short rsrcId){
/*
* Returns centering point for the topLeft corner of a dialog.
*/
Handle h = GetResource('DLOG',rsrcId);
Rect r = {0,0,0,0};
if(h){
r = *((Rect*)(*h));
DU_CenterRect(&r);
ReleaseResource(h);
}
return topLeft(r);
}
Point DU_StdPutWhere(void){
return DU_Where(putDlgID);
}
Point DU_StdGetWhere(void){
return DU_Where(getDlgID);
}
static short DU_Center(ResType type, short rsrcId){
/*
* Reads in an 'ALRT' or 'DLOG' rsrc template & centers it's display Rect.
*/
Handle h = GetResource(type,rsrcId);
if(h) DU_CenterRect((Rect*)(*h));
return rsrcId;
}
short DU_CenterALRT(short rsrcId){
return DU_Center('ALRT',rsrcId);
}
short DU_CenterDLOG(short rsrcId){
return DU_Center('DLOG',rsrcId);
}